package b3.widget.task
{
	import b3.config.*;
	import b3.model.*;
	import b3.net.*;
	import b3.util.*;
	import b3.widget.basic.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;
	
	public class TaskDialog extends BasicWidget
	{
		private var taskId:int;
		
		public function TaskDialog(taskId:int)
		{
			super();
			this.anchor = ANCHOR_MIDDLE_MIDDLE;
			this.taskId = taskId;
			var taskConfig:TaskConfig = Config.taskConfigs[taskId];
			//背景
			var TaskDialogBgr:Class = ResourceHelper.getInstance().getClassByName("TaskDialogBgr");
			addChild(new TaskDialogBgr());
			//标题
			var titleText:TextField = new TextField();
			titleText.selectable = false;
        	titleText.autoSize = TextFieldAutoSize.CENTER;
			titleText.defaultTextFormat = new TextFormat("微软雅黑", 18, 0x0066FF, true);
			titleText.filters = [new GlowFilter(0xFFFFFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			titleText.text = taskConfig.name;
			titleText.x = (this.width - titleText.width) / 2;
			titleText.y = 30;
			addChild(titleText);
			
			//图标
			var IconImage:Class = ResourceHelper.getInstance().getClassByName(taskConfig.iconImage);
			var iconImage:Sprite = new IconImage();
			iconImage.width = 60;
			iconImage.scaleY = iconImage.scaleX;
			iconImage.x = 50;
			iconImage.y = 95;
			addChild(iconImage);
			
			//描述文字
			var descriptionText:TextField = new TextField();
			descriptionText.selectable = false;
        	descriptionText.autoSize = TextFieldAutoSize.LEFT;
			descriptionText.defaultTextFormat = new TextFormat("微软雅黑", 18, 0x000000);;
			descriptionText.text = taskConfig.description;
			descriptionText.x = 138;
			descriptionText.y = 110;
			addChild(descriptionText);
			
			//提示信息
			var messageText:TextField = new TextField();
			messageText.selectable = false;
        	messageText.autoSize = TextFieldAutoSize.LEFT;
        	messageText.wordWrap = true;
        	messageText.width = 280;
			messageText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x000000);;
			messageText.text = taskConfig.message;
			messageText.x = 130;
			messageText.y = 165;
			addChild(messageText);
			
			//状态 
			var me:Player = PlayerManager.getInstance().me;
			var statusText:TextField = new TextField();
			statusText.selectable = false;
        	statusText.autoSize = TextFieldAutoSize.RIGHT;
			statusText.defaultTextFormat = new TextFormat("微软雅黑", 18, 0x0000FF);
			var num:int = 0;
			if (taskConfig.type == TaskConfig.TYPE_OBJECT_NUM)
			{
				num = me.packageModel.getObjectNum(taskConfig.requireIndex);
			}
			else if (taskConfig.type == TaskConfig.TYPE_BUILDING_NUM)
			{
				num = me.townModel.getBuildingNum(taskConfig.requireIndex);
			}
			statusText.text = num + "/" + taskConfig.requireNum;
			statusText.x = 390 - statusText.width;
			statusText.y = 110;
			addChild(statusText);
			
			//确定按钮
			var ButtonBgr:Class = ResourceHelper.getInstance().getClassByName("ButtonBgr0");
			var buttonOK:BasicButton = new BasicButton(ButtonBgr, "确定");
			buttonOK.x = (this.width  - buttonOK.width) / 2;
			buttonOK.y = 250;
			buttonOK.addEventListener(MouseEvent.CLICK, onButtonOKClick);
			addChild(buttonOK);
		}
		
		private function onButtonOKClick(event:MouseEvent):void
		{
			close();
		}
        
	}
}